import logging

import allure
from page_base.page_base import Base
from page_element.roncoo import *
from utils.timer import sleep

class RoncooAddMenu(Base):
    """登录页面"""
    def roncoo_login(self):
        # 打开
        self.open_url(url)
        self.maximize_window()
        with allure.step(f"输入用户名:"):
            self.send_keys(login_pe.login_username, 'admin')
        with allure.step(f"输入密码:"):
            self.send_keys(login_pe.login_pwd,'123456')
        # 强制等待输入验证码
        sleep(10)
        with allure.step("点击登录按钮"):
            self.click(login_pe.login_btn)
        #隐式等待---系统菜单
        self.driver.implicitly_wait(10)
        with allure.step('验证登录成功'):
            dy = self.text(login_pe.login_dy_text)
            print(dy)
            assert '系统菜单' in dy, f"断言失败(验证失败): 期望包含'系统菜单'，实际得到'{dy}'"
    """菜单管理添加权限"""
    def roncoo_add_permission(self,casename,expected, permission_name,permission_number,permission_desc):
        with allure.step('点击权限管理'):
            self.click(home_pe.rights_management_min)
        with allure.step('验证进入菜单管理页面'):
            dy = self.text(rolepage.permission_dy_text)
            print(dy)
            assert '权限' in dy, f"断言失败(验证失败): 期望包含'系统菜单'，实际得到'{dy}'"
        with allure.step('点击添加权限'):
            self.click(rolepage.permission_dy_text)
        with allure.step('输入权限名称'):
            self.send_keys(rolepage.permission_name_input,permission_name)
        with allure.step('输入权限标识'):
            self.send_keys(rolepage.permission_number_input, permission_number)
        with allure.step('输入权限描述'):
            self.send_keys(rolepage.permission_desc_input, permission_desc)
        with allure.step('点击保存按钮'):
            self.click(rolepage.save_permission_btn)
        with allure.step('验证过是否添加成功'):
            if '添加成功' in casename:
                dy = self.text(rolepage.dy)
                logging.info(f"预期结果：{expected}，实际结果: {dy}")
                assert expected in dy, f"断言失败(验证失败): 期望包含'{expected}'，实际得到'{dy}'"
                logging.info(f"验证成功,{casename}")
            elif '已添加过权限名称' in casename:
                dy = self.text(rolepage.dy_msg)
                logging.info(f"预期结果：{expected}，实际结果: {dy}")
                assert expected == dy, f"断言失败(验证失败): 期望等于'{expected}'，实际得到'{dy}'"
                logging.info(f"验证成功,{casename}")
            else:
                dy = self.text(rolepage.dy_msg)
                logging.info(f"预期结果：{expected}，实际结果: {dy}")
                assert expected == dy, f"断言失败(验证失败): 期望等于'{expected}'，实际得到'{dy}'"
                logging.info(f"验证成功,{casename}")





